<?php
session_start();
//$captcha = imagecreate(200,200);//kich thuoc khung 200x200(px)
$captcha = imagecreatefrompng('bg.png');

$black = imagecolorallocate($captcha, 0, 0, 0);
$white = imagecolorallocate($captcha, 255, 255, 255);
$red = imagecolorallocate($captcha, 255, 0, 0);
$xanhla = imagecolorallocate($captcha, 0, 255, 255);
$xanh = imagecolorallocate($captcha, 57, 57, 59);
//imagerectangle($captcha, 14, 0, 5, 25, $white);
//imagefilledrectangle($captcha, 20, 0, 10, 25, $white);
imageline($captcha, rand(0,100), rand(0,30), rand(0,100), rand(0,30), $red);// Ve duong line//(x,y,z,k)->(x,y)Toa do dinh dau va (z,k)dinh cuoi
imageline($captcha, rand(0,100), rand(0,30), rand(0,100), rand(0,30), $red);
imageline($captcha, rand(0,100), rand(0,30), rand(0,100), rand(0,30), $xanh);
imageline($captcha, rand(0,100), rand(0,30), rand(0,100), rand(0,30), $xanhla);

$font = 'arial.ttf';
//$text = 'hello world';

$string = md5(microtime());//(microtime() * mktime())-> e tao ra 1 so ngau nhien --> sau doa dung md5 ma hoa
$text = substr($string, 0, 6);// lay 6 ky tu dau tien
$_SESSION['macaptcha']=$text;
imagettftext($captcha, 14, 0, 5, 25, $red, $font, $text);

header('content-type: image/png');
imagepng($captcha);
imagedestroy($captcha);




?>